﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework.Graphics;

namespace Stonecode.Solar.ParticleEffectEditor
{
    public class NamedTexture2DCollection : List<NamedTexture2D>
    {
        public void GetTextureByName(string name, bool ignoreCase, out Texture2D tex)
        {
            if (ignoreCase)
            {
                for (int i = 0; i < this.Count; i++)
                {
                    if (this[i].TextureName.ToLower() == name.ToLower())
                    {
                        tex = this[i].Texture;
                        return;
                    }
                }
            }
            else
            {
                for (int i = 0; i < this.Count; i++)
                {
                    if (this[i].TextureName == name)
                    {
                        tex = this[i].Texture;
                        return;
                    }
                }
            }

            tex = null;
        }
        public int GetIndexByName(string name)
        {
            for (int i = 0; i < this.Count; i++)
            {
                if (this[i].TextureName.ToLower() == name.ToLower())
                    return i;
            }
            return -1;
        }

        public int RemoveTextureByName(string name)
        {
            string rmname = name.ToLower();
            int index = GetIndexByName(name);
            if (index > -1)
            {
                this[index].Texture.Dispose();
                this.RemoveAt(index);
            }

            return index;
        }
    }
}
